/**
 * MyMaxTempReducer.java
 * TODO
 */
package com.tjh.hadoop.mapred;

import java.io.IOException;
import java.net.InetAddress;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

/**
 * @author jahen
 * @date 2016年9月15日
 * @time 下午9:42:55
 * @category Hadoop MapReduce
 */
public class MyMaxTempReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
	@Override
	protected void reduce(Text key, Iterable<IntWritable> values,
			Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {
		
		InetAddress ip = InetAddress.getLocalHost();
		System.out.println("Reducer : " + ip);
		//
		int maxValue = Integer.MIN_VALUE;
		// 迭代求得最大值
		for (IntWritable value : values) {
			maxValue = Math.max(maxValue, value.get());
		}
		// 通过上下文对象写出最大值
		context.write(key, new IntWritable(maxValue));
	}
}
